package com.lagou.mapreduce;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class HomeworkDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        //创建configuration对象，job对象
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "HomeworkDriver");

        job.setJarByClass(HomeworkDriver.class);
//设置mapper和reducer
        job.setMapperClass(HomeworkMapper.class);
        job.setReducerClass(HomeworkReducer.class);
//设置map输出所用的key和value类
        job.setMapOutputKeyClass(HomeworkBean.class);
        job.setMapOutputValueClass(NullWritable.class);
//设置最终输出的类
        job.setOutputKeyClass(HomeworkBean.class);
        job.setOutputValueClass(NullWritable.class);
//设置reducetask的数量
        job.setNumReduceTasks(1);
//设置输入输出路径
        FileInputFormat.setInputPaths(job,new Path(args[0]));
        FileOutputFormat.setOutputPath(job,new Path(args[1]));
//提交任务
        boolean flag = job.waitForCompletion(true);
        System.exit(flag?0:1);
    }
}
